home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 April / MacFormat CD Edition MF36 (April 1996).iso / Shareware City / Developers / Tools Plus - GUI⁄Event libs / Tools Plus 2.6.1a Evaluat'n Kit / Tools Plus 2.6.1a / Tutorials / 6-Picture Buttons / Tutorial.p < prev    next >
Encoding:
Text File  |  1995-08-25  |  6.3 KB  |  170 lines  |  [TEXT/PJMM]

  1. {    Tools Plus Tutorial    - -    Picture Buttons    }
  2.  
  3. {    NOTE:    }
  4. {    The MWERKS compiler directived ($IFC MWERKS) indicates code that is compiled only by    }
  5. {    the CodeWarrior compiler.  THINK Pascal and Metrowerks CodeWarrior Pascal have    }
  6. {    _slight_ differences, and this compiler directive lets you use one source for both compilers.    }
  7. {    You can remove the code that does not pertain to your compiler.    }
  8.  
  9.  
  10. program Tutorial;
  11.     uses
  12. {$IFC MWERKS}
  13.         Dialogs, Fonts, Processes, SegLoad, TextEdit, ToolsPlus, Windows;
  14. {$ELSEC}
  15.         ToolsPlus;
  16. {$ENDC}
  17.  
  18.  
  19.     const
  20.     { Constants for picture buttons (for more readable code)… }
  21.         LeftAlignButton = 3;
  22.         CenterAlignButton = 4;
  23.         RightAlignButton = 5;
  24.         JustifyButton = 6;
  25.         CutButton = 7;
  26.         BucketButton = 8;
  27.         ClipboardButton = 9;
  28.         PrinterButton = 12;
  29.         ModemButton = 13;
  30.         ScrollingButton = 15;
  31.         PowerButton = 23;
  32.         DoneButton = 25;
  33.  
  34.     { Constants for picture button images (for more readable code)… }
  35.         PrinterIcon = 150;
  36.         ModemIcon = 151;
  37.         LeftAlignIcon = 408;
  38.         CenterAlignIcon = 409;
  39.         RightAlignIcon = 410;
  40.         JustifyIcon = 411;
  41.         CutIcon = 412;
  42.         BucketIcon = 413;
  43.         ClipboardIcon = 414;
  44.         PowerIcon = 450;
  45.         ScrollingIcon = 458;
  46.         DoneIcon = 464;
  47.  
  48.  
  49.     var
  50.         Poll: TPPollRecord;            {Polling record to retrieve event information}
  51.         ExitTheDemo: boolean;        {Should the demo terminate?}
  52.  
  53.         theButton: integer;            {Button counter    }
  54.  
  55.  
  56.  
  57.  
  58. {    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    }
  59.     procedure ApplicationInitialization;
  60.         const
  61.             DemoWindow1 = 1;
  62.             DemoWindow2 = 2;
  63.  
  64.         { This big 3D button stays down when selected, lightens when selected,}
  65.         {    and gets whited out when disabled…    }
  66.             Big3Dspec = picbutLockSelected + picbutBigSICN3D + picbutSelectLightenSICN3D + picbutDimUsingWhite;
  67.  
  68.         { This small 3D button pops back up after being selected, lightens when    }
  69.         {    selected, and gets whited out when disabled…    }
  70.             Small3Dspec = picbutSelectLightenSICN3D + picbutDimUsingWhite;
  71.  
  72.         { This ordinary icon (printer and modem) is selected when the mouse-down occurs,    }
  73.         {    stays down when selected, darkens when selected.  When disabled, a white        }
  74.         {    screen effect is used and the border is preserved…    }
  75.             OrdinaryIconSpec = picbutInstantEvent + picbutLockSelected + picbutSelectDarken + picbutDimUsingWhite + picbutDimLeaveBorder;
  76.  
  77.     begin
  78.     {    Do all the application setup before you start polling for events…    }
  79.         AppleMenu('');
  80.         Menu(1, 0, enabled, 'File');
  81.         Menu(1, 1, enabled, 'Quit/Q');
  82.         UpdateMenuBar;
  83.  
  84.  
  85.         WindowOpen(DemoWindow1, 0, 0, 215, 160, 'Dummy Window', noGrowDocProc + wCenter, NoGoAway, NotModal);
  86.         WindowOpen(DemoWindow2, 0, 0, 215, 160, 'Picture Buttons', noGrowDocProc + wTile, NoGoAway, NotModal);
  87.  
  88.         NewPictButton(LeftAlignButton, 12, 8, LeftAlignIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
  89.         NewPictButton(CenterAlignButton, 35, 8, CenterAlignIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
  90.         NewPictButton(RightAlignButton, 58, 8, RightAlignIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
  91.         NewPictButton(JustifyButton, 81, 8, JustifyIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
  92.  
  93.         NewPictButton(CutButton, 128, 9, CutIcon, Small3Dspec, enabled, notSelected, 0, 0, 0);
  94.         NewPictButton(BucketButton, 151, 9, BucketIcon, Small3Dspec, enabled, notSelected, 0, 0, 0);
  95.         NewPictButton(ClipboardButton, 174, 9, ClipboardIcon, Small3Dspec, enabled, notSelected, 0, 0, 0);
  96.  
  97.         NewPictButton(PrinterButton, 22, 50, PrinterIcon, OrdinaryIconSpec, enabled, selected, 0, 0, 0);
  98.         NewPictButton(ModemButton, 63, 50, ModemIcon, OrdinaryIconSpec, enabled, notSelected, 0, 0, 0);
  99.  
  100.     {This is a dual state button (Power-On, Power-Off), so it is considered to be a "Multi-Stage" button (Off=0, 1=On).}
  101.     {    The button's value changes automatically when selected by the user.  The values 'wrap' to allow 1 (on) to    }
  102.     {    start back at 0 (off) again.  An alternate icon is used to depict the selected button (down position), and        }
  103.     {    disabled button for maximum visual control…                                                                }
  104.         NewPictButton(PowerButton, 131, 50, PowerIcon, picbutMultiStage + picbutAutoValueChg + picbutValueWrap + picbutSelectAltImage + picbutDimAltImage, enabled, notSelected, 0, 0, 1);
  105.  
  106.     {This scrolling button has nine icon images in its SICN resource.  It keeps producing doPictButton events while    }
  107.     {    the mouse is held down.  The button's value changes automatically with the top 1/2 of the button                }
  108.     {    incrementing the value and the bottom 1/2 decrementing it.  This is a BIG 3D button that looks 'pushed' when}
  109.     {    selected (not darker or ligher)…    }
  110.         NewPictButton(ScrollingButton, 172, 55, ScrollingIcon, picbutRepeatEvents + picbutAutoValueChg + picbutTopBottomSplit + picbutBigSICN3D + picbutSelectPushedSICN3D, enabled, notSelected, 1, 5, 9);
  111.  
  112.     {This is a really simple push-button that uses an alternate icon when the button is selected.    }
  113.     {    When disabled, a white screen is overlayed and the border is preserved.    }
  114.         NewPictButton(DoneButton, 131, 130, DoneIcon, picbutSelectAltImage + picbutDimUsingWhite + picbutDimLeaveBorder, enabled, notSelected, 0, 0, 0);
  115.  
  116.         ExitTheDemo := false;
  117.     end;
  118.  
  119.  
  120. {    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    }
  121. begin
  122. {$IFC MWERKS}
  123. {Toolbox initialization - - Done automatically by THINK Pascal}
  124.     InitGraf(@qd.thePort);
  125.     InitFonts;
  126.     InitWindows;
  127.     InitMenus;
  128.     TEInit;
  129.     InitDialogs(nil);
  130.     MaxApplZone;
  131. {$ENDC}
  132.  
  133.     if not InitToolsPlus(0, 2, UseColor) then
  134.         ExitToShell;
  135.  
  136.     ApplicationInitialization;
  137.  
  138.     while not ExitTheDemo do    {Main Event Loop}
  139.         if PollSystem(Poll) then    {If an event is available, process the event…}
  140.  
  141.             case Poll.What of
  142.  
  143.                 doPictButton: 
  144.                     case Poll.Button.Num of
  145.  
  146.                         LeftAlignButton, CenterAlignButton, RightAlignButton, JustifyButton:
  147.             {    Cycle through the group and turn off the buttons that weren't clicked (deselect them)…}
  148.                             for theButton := LeftAlignButton to JustifyButton do
  149.                                 SelectPictButton(theButton, theButton = Poll.Button.Num);
  150.  
  151.                         PrinterButton, ModemButton:
  152.             {    Cycle through the group and turn off the buttons that weren't clicked (deselect them)…}
  153.                             for theButton := PrinterButton to ModemButton do
  154.                                 SelectPictButton(theButton, theButton = Poll.Button.Num);
  155.  
  156.                         DoneButton: 
  157.                             ExitTheDemo := true;
  158.  
  159.                         otherwise    {Ignore all other buttons}
  160.                     end;
  161.  
  162.                 doMenu:    {The only menu item available is 'Quit'…}
  163.                     ExitTheDemo := true;
  164.  
  165.                 doChgWindow:    {Activate the clicked window…    }
  166.                     ActivateWindow(Poll.Window);
  167.  
  168.                 otherwise    {All other events are ignored}
  169.             end
  170. end.